package com.guojian.jdbc.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.BeanPropertyRowMapper;

import com.guojian.jdbc.JdbcDataFormat;

public class BeanPropertyDataFormatRowMapper<T> extends BeanPropertyRowMapper<T> {

    private JdbcDataFormat<T> format;

    public BeanPropertyDataFormatRowMapper(Class<T> mappedClass) {
        super(mappedClass);
    }

    public BeanPropertyDataFormatRowMapper(Class<T> mappedClass, JdbcDataFormat<T> format) {
        super(mappedClass);
        this.format = format;
    }


    @Override
    public T mapRow(ResultSet rs, int rowNumber) throws SQLException {
        T row = super.mapRow(rs, rowNumber);
        if (getFormat() != null) {
            format.formatRow(row);
        }
        return row;
    }

    public JdbcDataFormat<T> getFormat() {
        return format;
    }

    public void setFormat(JdbcDataFormat<T> format) {
        this.format = format;
    }


    public static void main(String[] args) {
    }
}
